import log from 'electron-log';
import Config from "../config/config";

const express = require('express')

const app = express()

// const ServerPort = Config.serverPort

app.use((req: any, res: any, next: any) => {
  res.header('Access-Control-Allow-Credentials', true)
  res.header('Access-Control-Allow-Origin', 'http://localhost:1212')
  res.header('Access-Control-Allow-Headers', 'Authorization,X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method' )
  res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PATCH, PUT, DELETE')
  res.header('Allow', 'GET, POST, PATCH, OPTIONS, PUT, DELETE')
  next();
});

app.use(express.static('E:\\eduPlayer'))



const setStaticPath = (filepath: string) => {
  app.use(express.static(filepath))
  log.info(`server static path: ${filepath}`)
}

const startServer = () => {
  const server = app.listen(Config.serverPort, function() {
    console.log('edu static server start:', server.address().port)
  })
}

export default {
  setStaticPath,
  startServer,
}